package cn.tedu.ivos.application.controller;


import cn.tedu.ivos.application.pojo.dto.ApplicationQuery;
import cn.tedu.ivos.application.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivos.application.pojo.vo.ApplicationVO;
import cn.tedu.ivos.application.service.ApplicationService;
import cn.tedu.ivos.base.response.JsonResult;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/application")
public class ApplicationController {
    @Autowired
    private ApplicationService applicationService;

    @PostMapping("save")
    public JsonResult saveApplication(ApplicationSaveParam applicationSaveParam){
        log.debug("保存用车申请:applicationSaveParam={}",applicationSaveParam);
        applicationService.saveApplication(applicationSaveParam);
        return JsonResult.ok();
    }

    @GetMapping("select")
    public JsonResult selectApplication(ApplicationQuery ApplicationQuery){
        log.debug("查询用车申请:ApplicationQuery={}",ApplicationQuery);
        List<ApplicationVO> list = applicationService.selectApplication(ApplicationQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("cancel/{id}")
    public JsonResult cancelApplication(@PathVariable Long id){
        log.debug("取消用车申请:id={}",id);
        applicationService.cancelApplication(id);
        return JsonResult.ok();
    }

    @PostMapping("distribute/{id}/{vehicleId}")
    public JsonResult distribute(@PathVariable Long id,@PathVariable Long vehicleId){
        log.debug("分配车辆:id={},vehicleId={}",id,vehicleId);
        applicationService.distribute(id,vehicleId);
        return JsonResult.ok();
    }

    @PostMapping("back/{applicationId}/{vehicleId}")
    public JsonResult back(@PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("归还车辆:applicationId={},vehicleId={}",applicationId,vehicleId);
        applicationService.back(applicationId,vehicleId);
        return JsonResult.ok();
    }
}
